package com.kelvin.paopao.module.main.date.publish.sport;

import com.hyphenate.easeui.utils.SpUtil;
import com.kelvin.kelvinlib.utils.ToastUtil;
import com.kelvin.paopao.api.RetrofitService;
import com.kelvin.paopao.api.responseBean.CommonListResponse;
import com.kelvin.paopao.utils.DialogMaker;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer;

/**
 * Created by Administrator on 2017/5/14.
 */

public class PublishSportPresenter implements IPublishSportPresenter {

    private PublishSportActivity mView;

    public PublishSportPresenter(PublishSportActivity view) {
        this.mView = view;
    }

    @Override
    public void getData(boolean isRefresh) {

    }

    @Override
    public void getMoreData() {

    }


    @Override
    public void publishSport(String oAddress, String item_title, String time,
                             String osex, String opayMode, String isTip, String tipPrice,
                             String hours, String introduce, String img1, String img2,
                             String img3, String oAddressId,String oDate) {
        RetrofitService.publishDate("order_add", item_title, oAddress, osex, opayMode, isTip, tipPrice
                , hours, "0", "0", introduce, "1", SpUtil.getLoginHuanxin_id(mView),
                img1, img2, img3, oAddressId,oDate).doOnSubscribe(new Consumer<Disposable>() {
            @Override
            public void accept(@NonNull Disposable disposable) throws Exception {
                DialogMaker.showProgressDialog(mView, "邀约发布中，请稍候~~");
            }
        }).subscribeOn(AndroidSchedulers.mainThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<CommonListResponse>() {
            @Override
            public void accept(@NonNull CommonListResponse commonListResponse) throws Exception {
                if (commonListResponse.getReason().equals("成功")) {
                    mView.finish();
                    ToastUtil.showToast(mView, "邀约发布成功");
                }
                DialogMaker.diamiss();
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(@NonNull Throwable throwable) throws Exception {
                DialogMaker.diamiss();
            }
        }, new Action() {
            @Override
            public void run() throws Exception {
                DialogMaker.diamiss();
            }
        });
    }
}
